package com.fenshi.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fenshi.until.CookicUntil;
import com.fenshi.until.MethodCode;

import java.util.UUID;

/**
 * Created by lilongfei on 15/5/1.
 */
public class RequestBean {
    private float id = 1L;

    private String requestSession;
    private String requestCode;
    private RequestContent requestContent;

    public RequestBean(){
        requestSession = UUID.randomUUID().toString();
        requestContent = new RequestContent();

    }

    public String getRequestSession() {
        return requestSession;
    }

    public void setRequestSession(String requestSession) {
        this.requestSession = requestSession;
    }

    public String getRequestCode() {
        return requestCode;
    }

    public void setRequestCode(String requestCode) {
        this.requestCode = requestCode;
    }

    public RequestContent getRequestContent() {
        return requestContent;
    }

    public void setRequestContent(RequestContent requestContent) {
        this.requestContent = requestContent;
    }

    public void setRequestParams(String params){
        requestContent.setRequestParams(JSON.parseObject(params));
    }

    public void setRequestParams(Object bean){
        requestContent.setRequestParams((JSONObject) JSON.toJSON(bean));

    }

    public void setRequestContentCurrentPage(int currentPage){
        requestContent.setCurrentPage(currentPage);
    }

    public void setUserSession(String session){
        requestContent.setUserSession(session);
    }

    class RequestContent {
        private String userSession;
        private PageInfo pageInfo;
        private JSONObject requestParams;

        public RequestContent(){
            pageInfo = new PageInfo();
            requestParams = new JSONObject();
            if(CookicUntil.getUser()!=null && CookicUntil.getUser().getUserId()!=null)
                userSession = CookicUntil.getUser().getUserId();
            else
                userSession = "";
        }

        public String getUserSession() {
            return userSession;
        }

        public void setUserSession(String userSession) {
            this.userSession = userSession;
        }

        public PageInfo getPageInfo() {
            return pageInfo;
        }

        public void setPageInfo(PageInfo pageInfo ) {
            this.pageInfo = pageInfo;
        }

        public JSONObject getRequestParams() {
            return requestParams;
        }

        public void setRequestParams(JSONObject params) {
            this.requestParams = params;
        }

        public void setCurrentPage(int current){
            pageInfo.setCurrentPage(current);
        }

    }

    class PageInfo{
        private int pageSize;
        private int currentPage;

        public PageInfo(){
            setPageSize(MethodCode.PAGE_SIZE);
        }

        public int getPageSize() {
            return pageSize;
        }

        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }

        public int getCurrentPage() {
            return currentPage;
        }

        public void setCurrentPage(int currentPage) {
            this.currentPage = currentPage;
        }
    }

}
